package com.example.arithmeticleetcode.leetcode;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: arithmetic-leetcode
 * @description: 1480. 一维数组的动态和
 * @author: FangZhen
 * @create: 2020-06-16 10:41
 **/
public class Demo29 {

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4};
        int[] nums1 = {1, 1, 1, 1, 1};
        int[] nums2 = {3, 1, 2, 10, 1};
        runningSum(nums);
        runningSum(nums1);
        runningSum(nums2);

        List<User> list = new ArrayList<>();

        for (int i = 0; i < 1000; i++) {
            list.add(new User("真名" + i, "昵称:" + i, i));
        }

        long start1 = System.currentTimeMillis();
        List<String> nameList1 = new ArrayList<>();
        List<String> nickNameList1 = new ArrayList<>();
        List<Integer> ageList1 = new ArrayList<>();
        list.forEach(user -> {
            nameList1.add(user.getName());
            nickNameList1.add(user.getNickName());
            ageList1.add(user.getAge());
        });
        Long end1 = System.currentTimeMillis();

        System.out.println("非流式处理" + (end1 - start1));

        long start = System.currentTimeMillis();
        List<String> nameList = list.stream().map(User::getName).collect(Collectors.toList());
        List<String> nickNameList = list.stream().map(User::getNickName).collect(Collectors.toList());
        List<Integer> ageList = list.stream().map(User::getAge).collect(Collectors.toList());
        Long end = System.currentTimeMillis();

        System.out.println("流式处理" + (end - start));

        List<String> userList = new ArrayList<>();
        System.out.println(userList.size() == 0L);

    }

    public static int[] runningSum(int[] nums) {
        int length = nums.length;
        int[] arr = new int[length];
        int sum = 0;
        for (int i = 0; i < length; i++) {
            sum += nums[i];
            System.out.println(sum);
            arr[i] = sum;
        }
        return arr;
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class User {
    private String name;

    private String nickName;

    private Integer age;
}
